#pragma once

enum NDir {
	START,
	NORTH,
	EAST,
	SOUTH,
	WEST,
	RESET
};

typedef void * (*Task) (void*);
class WalkingCursor {
public:
	WalkingCursor():x(0),y(0),Dir(START+1),Move(1),yRange(1),MaxMove(1),Stop(false){}
	int x,y;
	int Dir;
	int Move;
	int yRange;
	int MaxMove;
	int yMax;
	bool Stop;
	int itterator;
	virtual void Init(int a_xP,int a_yP,int a_MaxMove,int a_yRange) {
		x = a_xP;
		y = a_yP;
		MaxMove = a_MaxMove;
		itterator = 0;
		yRange = a_yRange;
		yMax = a_yP + MaxMove / 2;
		Dir = START+1;
		Stop = false;
	}
	void Walk() {
		//Prints all the pixels in a circular method around it
		WalksinDir();
	}
	virtual void WalksinDir() {
		static int Change = 0;
		
		if(itterator++ >= Move) {
			itterator -= Move;
			if(Dir++ == RESET-1) {
				Dir = START+1;
			}
			if(Change++ == 1) {
				Move++;
				Change = 0;
			}
		}

		Step();
		if(Move == MaxMove && itterator == MaxMove)
		{
			Stop = true;
		}
	}

	void Step() {
		switch(Dir) {
		case NORTH:
			y--;
			break;
		case SOUTH:
			y++;
			break;
		case EAST:
			x++;
			break;
		case WEST:
			x--;
			break;
		default:	break;
		}
	}
	void DoTask() {
		/*Sleep(10);
		if(x >= 0 && y >= 0) {
			MoveCursor(x,y);
			printf("x");
		}*/
	}
	bool InBounds() {
		if( y <= yMax - yRange && y >= yMax - MaxMove + yRange ) {
			return true;
		}
		return false;
	}
};

class RWalkingCursor : public WalkingCursor {
public:
	bool NextTurn;
	RWalkingCursor():WalkingCursor(),NextTurn(false){}
	void Init(int a_xP,int a_yP,int a_MaxMove,int a_yRange) {
		x = a_xP - a_MaxMove / 2;
		y = a_yP + a_MaxMove / 2;
		MaxMove = a_MaxMove;
		Move = a_MaxMove;
		yRange = a_yRange;
		itterator = 0;
		yMax = a_yP + MaxMove / 2;
		NextTurn = false;
		Dir = START+1;
		Stop = false;
	}
	virtual void WalksinDir() {
		static int Change = 0;
		
		if(++itterator > Move) {
			itterator = 1;
			if(Dir++ == RESET-1) {
				Dir = START+1;
			}
			if(Change++ == 1) {
				Move--;
				Change = 0;
			}
		}

		Step();

		
		if(NextTurn){
			Stop = true;return;
		}
		if(Move == 1 && itterator == 1)
		{
			NextTurn = true;
		}
	}
};

struct WorldChange {
	short x,y;
	unsigned int Data;
	WorldChange() :x(0),y(0),Data(0) {}
	WorldChange(short a_x,short a_y) : x(a_x), y(a_y), Data(0) {}
	WorldChange(short a_x,short a_y,unsigned int a_Data) : x(a_x), y(a_y), Data(a_Data) {}
	void Set(short a_x,short a_y,unsigned int a_Data) {
		x = a_x;
		y = a_y;
		Data = a_Data;
	}
	/*
	short x2
	int
	X Y
	UNSIGNED int

	*/
};